﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows;
using TransactionServer.General_Classes;

namespace TransactionServer.ActivityDesign.Components
{
    class OSDictionaryStringControl77 : ComboBox
    {
        public static readonly DependencyProperty ConnectionProperty =
        DependencyProperty.Register("Connection", typeof(string), typeof(OSDictionaryStringControl77),
        new FrameworkPropertyMetadata(
            String.Empty,
            FrameworkPropertyMetadataOptions.AffectsMeasure,
            new PropertyChangedCallback(GetDictionaryList),
            null
        ));

        public string Connection
        {
            get
            {
                return (string)GetValue(ConnectionProperty);
            }
            set
            {
                SetValue(ConnectionProperty, value);
            }
        }

        public static void GetDictionaryList(DependencyObject dObject, DependencyPropertyChangedEventArgs eventArgs)
        {
            var control = (OSDictionaryStringControl77)dObject;
            if (!String.IsNullOrEmpty(control.Connection))
            {
                List<String> dictionary = StaticContext.context.GetEntities(control.Connection).FindAll(d => d.StartsWith("Справочник."));
                List<String> source = new List<string>();
                dictionary.ForEach(d => source.Add(d.Replace("Справочник.", "")));
                control.ItemsSource = source;
            }
        }
    }
}
